<template>
  <div class="paramConfig">
    <DFPageList ref="dfPageListRef" :pageOptions="pageOptions" />
  </div>
</template>

<script lang="ts" setup name="Machine">
  import lang from './lang';
  import { pageMachine, addMachine, updateMachine, delMachine } from '@/api/base/machine';
  import { useMixins } from '@/hooks/useMixins';
  import { isOpenMultiLineList } from '../../gather/machine/components/data';
  import { useProjectSettingStore } from '@/store/modules/projectSetting';

  const projectStore = useProjectSettingStore();

  const { loadLangFn } = useMixins();

  const dfPageListRef: any = ref(null);

  loadLangFn(lang);

  const pageOptions = {
    searchForm: {
      formSchemas: [
        {
          label: 'machineName',
          component: 'NInput',
        },
        {
          label: 'machineCode',
          component: 'NInput',
        },
      ],
    },
    table: {
      columns: [
        {
          width: 120,
          label: 'machineName',
        },
        {
          width: 120,
          label: 'machineCode',
        },
        {
          label:'machineModel'
        },
        {
          width: 120,
          label: 'remark',
          common: true,
        },
      ],
      action: {
        columns: [
          {
            label: 'edit',
          },
          {
            label: 'delete',
          },
        ],
      },
      operaColumn: [
        {
          label: 'add',
        },
      ],
      requestFn: pageMachine,
      delRequestFn: delMachine,
    },
    modalFormDialog: {
      formSchemas: [
        {
          label: 'machineName',
          editDialogDisabled: true,
          required: true,
        },
        {
          label: 'machineCode',
          editDialogDisabled: true,
          required: true,
        },
        {
          label:'machineModel'
        },
        {
          width: 120,
          label: 'unitNum',
          component: 'NInputNumber',
          required: true,
          requiredRulesType:'number',
          componentProps: {
            defaultValue: 4,
            maxlength: 50,
            min: 1,
            max: 10,
            precision: 0,
            clearable: true,
            showButton: false,
          },
        },
        {
          label: 'mac',
          component: 'NInput',
          defaultValue: projectStore.mac,
          componentProps: {
            onUpdateValue(_v: string, _option: any, updateFormModelFn: any, formModel: any) {
              if (formModel && formModel.mac) {
                typeof updateFormModelFn === 'function' &&
                  updateFormModelFn({
                    mac: formModel.mac.toLowerCase().replace(/-/g, ':'),
                  });
              }
            },
          },
        },
        {
          label: 'ip',
          defaultValue: projectStore.ip,
        },
        {
          label: 'factoryName',
        },
        {
          label: 'factoryChildName',
        },
        {
          label: 'hasCleanUpUnit',
          component: 'NSelect',
          options: isOpenMultiLineList,
          required: true,
          requiredRulesType: 'number',
          defaultValue: 0,
        },
        {
          label: 'hasDieCuttingUnit',
          component: 'NSelect',
          options: isOpenMultiLineList,
          required: true,
          requiredRulesType: 'number',
          defaultValue: 1,
        },
        {
          label: 'hasPreloadingUnit',
          component: 'NSelect',
          options: isOpenMultiLineList,
          required: true,
          requiredRulesType: 'number',
          defaultValue: 0,
        },
        {
          label: 'hasSlottedUnit',
          component: 'NSelect',
          options: isOpenMultiLineList,
          required: true,
          requiredRulesType: 'number',
          defaultValue: 1,
        },
        {
          label: 'hasFeedingUnit',
          component: 'NSelect',
          options: isOpenMultiLineList,
          required: true,
          requiredRulesType: 'number',
          defaultValue: 1,
        },
        {
          label: 'machineStatusNegation',
          component: 'NSelect',
          options: isOpenMultiLineList,
          required: true,
          requiredRulesType: 'number',
          defaultValue: 0,
        },
        {
          label: 'paperStatusNegation',
          component: 'NSelect',
          options: isOpenMultiLineList,
          required: true,
          requiredRulesType: 'number',
          defaultValue: 0,
        },
        {
          label: 'machinePicture',
          component: 'UploadImage',
          componentProps: {
            max:1
          }
        },
        {
          label: 'remark',
          common: true,
          type: 'textarea',
        },
      ],
      addDataFn: addMachine,
      updateDataFn: updateMachine,
    },
  };

  // nextTick(() => {
  //   dfPageListRef.value && dfPageListRef.value.openModalFn();
  // });
</script>
